<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="" />
        <meta name="format-detection" content="telephone=no">
        <title>收货地址</title>
        <link rel="stylesheet" href="../css/address.css">
        <link rel="stylesheet" href="../css/address/address.css">
        
		<%@ include file="../general.jsp"%>
    </head>
    <body ontouchstart>
        <section class="ui-container">
            <ul class="add_con" id="list">
            	<!-- 用户收货地址 -->
            </ul>
            <div class="loading" id="loading"><a href="address1.do">添加地址</a></div>
        	<div class="return_btn">
				<a href="#">
					<div class="return_btn_in">
						<img src="../images/weip.png" alt="">  
						<p>（返回微交易）</p>
					</div>
				</a>
			</div>
        </section><!-- /.ui-container-->
        <input type="hidden" name="${_csrf.parameterName}"  value="${_csrf.token}" />
    </body>
</html>
<script>
$(function(){
	getAddress(1);
});

function updateaddress(id,action){
	$.ajax({
		type : 'POST',
		url : "updateAddress.do",
		async : 'true',
		data: {
			"id":id,
			"action":action,
			"_csrf" : $('[name="_csrf"]').val()
		},
		dataType : 'json',
		success : function(data){
			var result=data.result;
			if(result==1){
				alert("设置默认收货地址成功");
			}else if(result==2)
				alert("删除收货地址成功");
			
			getAddress(1);
		}
	});
}


function getAddress(offset){
	$.ajax({
		type : 'POST',
		url : "getUserAllAddress.do",
		async : 'true',
		data: {
			"offset":offset,
			"_csrf" : $('[name="_csrf"]').val()
		},
		dataType : 'json',
		success : function(data){
			var addresslist=data.item.resultList;
			var html="";
			for(var i=0;i<addresslist.length;i++){
				var id=addresslist[i].id;
				html +="<li>";
				html +="<div class='add_con_in1'>";
				html +="<div class='add_left'>"+addresslist[i].userName+"</div>";
				html +="<div class='add_zhong'></div>";
				html +="<div class='add_right'>"+addresslist[i].phone+"</div>";
				html +=" </div>";
				html +="<div class='add_con_in2'>";
				html +="<p>地址："+addresslist[i].address+"</p>";
				html +="</div>";
				html +="<div class='add_con_in3'>";
				html +="<div class='add_in3_left'>";
				if(addresslist[i].status==1){
					html +="<span class='cbox checked' onclick='this.className=/checked/ig.test(this.className)?this.className.replace('checked',''):(this.className+' checked')'></span>";
					html +="<span>默认地址</span>";
				}else{
					html +="<span class='cbox' onclick=\"this.className=/checked/ig.test(this.className)?this.className.replace('checked',''):(this.className+' checked');updateaddress("+id+",'update');\"></span>";
					html +="<span>默认地址</span>";
				}
				html +="</div>";
				html +="<div class='add_in3_right'>";
				html +="<span><img src='../images/bi.png' alt=''><a href='address1.do?id="+id+"'>编辑</a></span>";
				html +="<span><img src='../images/sc.png' alt=''><a href=\"javascript:updateaddress("+id+",'delete');\">删除</a></span>";
                html +="</div>";
                html +="</div>";
                html +="</li>";
			}
			$("#list").html(html);
		}
	});
}


</script>